<template>
  <el-container class="home-sjfxzx" v-loading="loading">
    <el-header class="header search-header">
      <el-form
        ref="ruleFormRef"
        class="between-form"
        :model="search"
        :inline="true"
      >
        <div>
          <el-form-item label="数据表名称" prop="objectNameOrChn">
            <el-input
              v-model="search.objectNameOrChn"
              placeholder="请输入数据表名称"
              clearable
            />
          </el-form-item>

          <el-form-item label="责任科室" prop="belongOrgId">
            <el-select
              v-model="search.belongOrgId"
              placeholder="请选择"
              style="min-width: 120px"
              clearable
            >
              <el-option key="" label="全部" value=""> </el-option>
              <el-option
                v-for="item in doorList"
                :key="item.orgId"
                :label="item.orgName"
                :value="item.orgId"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="业务分类" prop="busiTypeCode">
            <el-select
              v-model="search.busiTypeCode"
              placeholder="请选择"
              style="min-width: 120px"
              clearable
            >
              <el-option key="" label="全部" value=""> </el-option>
              <el-option
                v-for="item in sortList"
                :key="item.busiTypeCode"
                :label="item.busiTypeName"
                :value="item.busiTypeCode"
              />
            </el-select>
          </el-form-item>
        </div>

        <el-form-item>
          <el-button
            type="primary"
            class="search-btn"
            @click="getSearch(ruleFormRef)"
          >
            查询
          </el-button>
          <el-button @click="reset(ruleFormRef)" class="reset-btn"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </el-header>
    <el-header class="header">
      <div class="header-l">
        <el-icon color="#2263BF"><Operation /></el-icon>
        <span class="text">公共监管</span>
      </div>
      <div class="header-r">
        <span>数据{{ total }}条</span>
        <el-divider direction="vertical" />
        <span>表{{ total }}张</span>
      </div>
    </el-header>
    <el-main>
      <el-container>
        <el-main>
          <el-container>
            <el-main class="container bc-table">
              <el-table
                :data="objecInfo.tableData"
                style="width: 100%; height: 100%"
              >
                <el-table-column prop="objectName" label="数据表名称" />
                <el-table-column prop="objectDesc" label="数据描述" />
                <el-table-column prop="belongOrgName" label="责任科室" />
                <el-table-column prop="busiTypeNames" label="业务分类">
                  <template #default="scope">
                    <span>{{ scope.row.busiTypeNames.join(",") }}</span>
                  </template>
                </el-table-column>
                <el-table-column prop="dataAmount" label="数据条数">
                  <template #default="scope">
                    <span>{{ scope.row.dataAmount }}</span>
                  </template>
                </el-table-column>
                <el-table-column prop="lastModify" label="更新时间">
                  <template #default="scope">
                    <span>{{ formatDateTime(scope.row.lastModify) }}</span>
                  </template>
                </el-table-column>
                <el-table-column prop="createTime" label="创建时间">
                  <template #default="scope">
                    <span>{{ formatDateTime(scope.row.createTime) }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="操作">
                  <template #default="scope">
                    <el-button
                      link
                      type="primary"
                      size="small"
                      @click="handleClick(scope.row)"
                      >查看</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
            </el-main>
            <el-footer class="footer mt20">
              <el-pagination
                v-model:current-page="tableField.pageNo"
                v-model:page-size="tableField.pageSize"
                :page-sizes="[10, 20, 30, 50, 100]"
                layout="sizes, prev, pager, next, jumper"
                :total="total"
                :background="true"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                prev-text="上一页"
                next-text="下一页"
              />
            </el-footer>
          </el-container>
        </el-main>
      </el-container>
    </el-main>
    <!-- 抽屉 -->
    <Detail
      :currentRow="currentRow"
      v-if="showDetail"
      @close="showDetail = false"
    ></Detail>
  </el-container>
</template>

<script setup>
import { onMounted, ref, reactive, watch } from "vue";
import { useRouter, useRoute } from "vue-router";
import { getTypeList, busioptions } from "@/api";
import { getsjqdList } from "@/api/sjqd";
import { Minxfun } from "@/utils/minxin";
const {
  handleSizeChange,
  handleCurrentChange,
  tableField,
  total,
  loading,
  formatDateTime,
} = Minxfun();
import Detail from "./detail.vue";
const router = useRouter();

const ruleFormRef = ref();
const search = reactive({
  objectNameOrChn: "",
  belongOrgId: "",
  busiTypeCode: "",
});

onMounted(() => {
  getType();
  getTableData();
});

// 获取部门
let doorList = ref([]);
let sortList = ref([]);
const getType = async () => {
  try {
    let res = await getTypeList({
      orgTypeCode: "office",
    });
    doorList.value = res.data;
    let res1 = await busioptions();
    sortList.value = res1.data;
  } catch (e) {
    console.log(e);
  }
};

const getSearch = () => {
  if (tableField.value.pageNo == 1) {
    getTableData();
  } else {
    tableField.value.pageNo = 1;
    getTableData();
  }
};

const reset = (ruleFormRef) => {
  ruleFormRef.resetFields();
  getTableData();
};

watch(
  tableField,
  (newVal, oldVal) => {
    getTableData();
  },
  { deep: true }
);
let objecInfo = reactive({
  tableData: [],
});
const getTableData = async () => {
  try {
    loading.value = true;
    let { data } = await getsjqdList({
      ...tableField.value,
      ...search,
      pageNum: tableField.value.pageNo,
      belongOrgId: search.belongOrgId || null,
    });
    loading.value = false;
    console.log({
      ...tableField.value,
      ...search,
      pageNum: tableField.value.pageNo,
    });
    objecInfo.tableData = data.objectList
    console.log(objecInfo.tableData);
    total.value = Number(data.total) || 0;
  } catch (e) {
    loading.value = false;
    console.log(e);
  }
};

let currentRow = ref(null);
let showDetail = ref(false);
const handleClick = (value) => {
  currentRow.value = value;
  showDetail.value = true;
};
</script>

<style lang="scss" scoped>
.home-sjfxzx {
  width: 100%;
  height: 100%;
  .header {
    min-height: 36px;
    line-height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
    overflow: hidden;
    margin-bottom: 18px;
    .header-l {
      display: flex;
      align-items: center;
      .text {
        font-family: PingFangSC, PingFang SC;
        font-weight: 600;
        font-size: 16px;
        color: #333333;
        line-height: 22px;
        letter-spacing: 1px;
        text-align: left;
        padding-left: 14px;
      }
    }
  }
  .container {
  }
}
.el-container {
  height: 100% !important;
  padding: 0 !important;
}
.el-header {
  height: auto !important;
  min-height: 36px !important;
}
.el-main {
  padding: 0 !important;
}
.search {
  margin: 0 50px;
}
.header-r {
  font-family: PingFangSC, PingFang SC;
  font-weight: 500;
  font-size: 14px;
  color: #666666;
}
</style>

<style>
.el-form-item__label {
  font-family: PingFangSC, PingFang SC;
  font-weight: 500;
  font-size: 14px;
  color: #333333;
}
</style>
